﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using HZ.MBSM.DBUtility;
public partial class HomePage_Company_rg : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Tuser.Attributes.Add("onblur", "test()");
        }
        string _strsele = "select isnull(isTrade_landing,0) as YBMstatus from account where accountid=1";
        Db db = new Db();
        DataTable dt = db.DataTable(_strsele);
        db.Close();
        if (dt != null && Convert.ToInt32(dt.Rows[0][0].ToString()) ==0)
        {
            dt.Dispose();
            Response.Write("<script >alert('企业预报名已结束！');window.opener=null;window.open('','_self');window.close();</script>");
        }
        dt.Dispose();

    }
    public string getcode()
    {

        int number;
        char code;

        StringBuilder checkCode = new StringBuilder();
        System.Random random = new Random();

        for (int i = 0; i < 5; i++)
        {
            number = random.Next();

            if (number % 2 == 0)
                code = (char)('0' + (char)(number % 10));
            else
                code = (char)('A' + (char)(number % 26));

            checkCode.Append(code.ToString());
        }
        HiddenField1.Value = checkCode.ToString().ToUpper();
        return checkCode.ToString().ToUpper();
    }
    //提交
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (!Tpwd.Text.Trim().Equals(Tpwd2.Text.Trim()))
        { 
            Response.Write("<script >alert('两次密码输入不一致！');</script>");
            return;
        }
        SqlParameter[] spata = new SqlParameter[]{
        new SqlParameter("@cname",SqlDbType.VarChar),
        new SqlParameter("@sort",SqlDbType.Int),
        new SqlParameter ("@usercde",SqlDbType.VarChar),
        new SqlParameter("@pwd",SqlDbType.VarChar),
        new SqlParameter ("@pnd",SqlDbType.VarChar),
        new SqlParameter ("@sucee",SqlDbType.Bit)
        };
        spata[0].Value = Tcomname.Text.Trim();
        spata[1].Value = RadioButtonList1.SelectedValue;
        spata[2].Value = Tuser.Text.Trim();
        spata[3].Value = SysFun.PasswordEncrypt(Tpwd.Text.Trim());
        spata[4].Value = HiddenField1.Value;
        spata[5].Direction = ParameterDirection.Output;
        try
        {
            Db db = new Db();
            db.ExecuteProcedure("P_companRg", spata);
            db.Close();
            if ((bool)spata[5].Value)//添加成功
            {
                Tcomname.Text = ""; Tuser.Text = "";
                Response.Write("<script >alert('注册成功！');window.close();</script>");
            }
            else //添加失败
            {
                Response.Write("<script >alert('注册失败，请重新注册！');window.opener=null;window.open('','_self');window.close();</script>");
            }
        }
        catch
        {
            Response.Write("<script >alert('注册失败，请重新注册！');window.opener=null;window.open('','_self');window.close();</script>");
        }
    }
}
